package team.pwy.mapper;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import team.pwy.pojo.entity.Collect;
import team.pwy.pojo.entity.Movie;
import team.pwy.pojo.entity.PwyViewingHistory;

import java.util.List;
import java.util.Map;

@Repository
public interface MovieMapper {

    // 正在热映
    @Select("select * from pwy.pwy_movie where status = #{value} order by recommend desc")
    List<Movie> findHotting(Integer status);

    // 今日票房
    @Select("select * from pwy.pwy_movie where status = #{value} order by grossed desc limit 5")
    List<Movie> findTopFive(Integer status);

    // 根据id进行查询单个电影
    @Select("select * from pwy.pwy_movie p left join pwy.pwy_type t on p.id=t.move_id where p.id =#{id}")
    Movie findById(Integer id);

    @Select("select * from pwy.pwy_movie order by duration desc")
    List<Movie> findByTime();

    @Select("select * from pwy.pwy_movie order by score desc")
    List<Movie> findByScore();

    @Select("select * from pwy.pwy_movie order by grossed desc")
    List<Movie> findByHot();

    @Select("select * from pwy.pwy_movie order by desire limit 10")
    List<Movie> findByDesire();

    List<Movie> findByType(String type);

    List sel(Integer q);

    @Select("select * from pwy.pwy_movie limit 4")
    List<Movie> findByActive();

    List<Movie> findByTypes(Map<String, Object> typesMap);

    @Insert("insert into pwy.pwy_collect(id,user_id,movie_id,movie_title,poster_img,movie_price,status,create_time) values (null,#{userId}, #{movieId}, #{movieTitle}, #{posterImg},#{moviePrice},#{status}, #{createTime})")
    Integer addCollect(Collect collect);

    @Delete("delete from pwy.pwy_collect where movie_id= #{id} and user_id=#{userId}")
    Integer delCollect(@Param("id") Integer id, @Param("userId") Integer userId);

    @Select("select * FROM pwy.pwy_collect where user_id= #{value} order by create_time desc")
    List<Collect> lookCollect(Integer userId);

    @Select("select * FROM pwy.pwy_viewing_history where user_id= #{value} order by create_time desc")
    List<PwyViewingHistory> lookHistory(Integer userId);

    @Select("select * from pwy.pwy_movie where status = #{value}")
    List<Movie> findByStatus(Integer status);

    @Select("select * from pwy.pwy_movie")
    List<Movie> findAll();

    @Update("update pwy.pwy_movie set grossed = grossed + #{grossed} where id = #{id}")
    Integer updateGrossed(double grossed, Integer id);
}
